//************************************************************************************************************
// CoNatural.Data.dll
// Author: Roger Torres
//************************************************************************************************************
// You can use, modify, and distribute the source code and executable programs based on the source code.
// This source code is provided "as is" and without warranties as to performance or merchantability. 
// The author and/or distributors of this source code may have made statements about this source code. 
// Any such statements do not constitute warranties and shall not be relied on by the user in deciding 
// whether to use this source code. This source code is provided without any express or implied warranties 
// whatsoever. Because of the diversity of conditions and hardware under which this source code may be used, 
// no warranty of fitness for a particular purpose is offered. The user is advised to test the source code 
// thoroughly before relying on it. The user must assume the entire risk of using the source code.
//************************************************************************************************************

using System;
using System.Collections.Generic;
using System.Reflection;
 
namespace CoNatural.Data {
   /// <summary>
   /// Script command used to execute dynamic sql statements
   /// </summary>
   public sealed class Script : ICommand {
		private string script;
		public IDictionary<string, object> Parameters { get; private set; }

		public Script(string script) {
			this.script = script;
		}

		public Script(string script, IDictionary<string, object> parameters) {
			this.script = script;
			Parameters = parameters;
		}

		public Script(string script, object parameters) {
			this.script = script;
			Parameters = new Dictionary<string, object>();
			foreach(PropertyInfo p in parameters.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public)) {
				Parameters.Add(p.Name, p.GetValue(parameters, null));
			}
		}

		#region ICommand Members

		public string GetScript() {
			return script; 
		}

		#endregion
	}
}
